package com.tengroup.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tengroup.entity.RuleEntity;
import com.tengroup.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rule")
public class RuleController {

    @Autowired
    private RuleService ruleService;

    /**
     * 新增考题规则
     */
    @PostMapping
    public void add(@RequestBody RuleEntity ruleEntity) {
        ruleService.save(ruleEntity);
    }

    /**
     * 根据 ID 查询考题规则
     */
    @GetMapping("/rule{id}")
    public RuleEntity getById(@PathVariable Long id) {
        return ruleService.getById(id);
    }

    /**
     * 更新考题规则
     */
    @PutMapping
    public void update(@RequestBody RuleEntity ruleEntity) {
        ruleService.updateById(ruleEntity);
    }

    /**
     * 根据 ID 删除考题规则
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        ruleService.removeById(id);
    }

    /**
     * 分页查询考题规则
     */
    @GetMapping("/page")
    public Page<RuleEntity> listByPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        return ruleService.page(new Page<>(pageNum, pageSize));
    }
}